package com.situ.mall.controller.back;

import java.util.Arrays;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.situ.mall.entity.Shipping;
import com.situ.mall.entity.Result;
import com.situ.mall.service.IShippingService;

@Controller
@RequestMapping("/shipping")
public class ShippingController {
	
	@Autowired
	private IShippingService shippingService;

	@RequestMapping("/selectAll.action")
	@ResponseBody
	public List<Shipping> selectAll() {
		System.out.println("ShippingController.selectAll()");
		return shippingService.selectAll();
	}
	

// 0. index.jsp点一下   跳转到这里    再转发到   Shipping_list。jsp
	@RequestMapping("/getShippingListJsp.action")
	public String getShippingListJsp() {
		System.out.println("ShippingController.getShippingListJsp()");
		return "shipping_list";
	}
// 1.查询 每页信息     返回Result到	Shipping_list.jsp
	@RequestMapping("/selectByPage.action")
	@ResponseBody
	public Result selectByPage( @RequestParam(defaultValue = "1")Integer page,  @RequestParam(defaultValue = "5")Integer limit) {
		System.out.println("ShippingController.selectByPage()");
		return shippingService.selectByPage(page,limit);
	}
	
// 2.批量删除
	@RequestMapping("/deleteAll.action")
	@ResponseBody
	public Result deleteAll(Integer[] ids) {  
		// 批量删除   好多个  所以接收数组
		System.out.println("ShippingController.deleteAll()");
		System.out.println(Arrays.toString(ids));
		
		boolean isSuccess = shippingService.deleteAll(ids);
		if (isSuccess) {
			return Result.success("删除成功");
		} else {
			return Result.error("删除失败");
		}
	}
	
// 3.删除
	@RequestMapping("/deleteById.action")
	@ResponseBody
	public Result deleteById(Integer id) {
		System.out.println("ShippingController.deleteById()");
		System.out.println("id="+id);
		
		boolean isSuccess = shippingService.deleteById(id);
		if (isSuccess) {
			System.out.println("删除成功");
			return Result.success("删除成功");
		}else {
			System.out.println("删除失败");
			return Result.error("删除失败");
		}
	}
	
}
